﻿using AuthCenter.Api.Read.Application.Command.User;
using AuthCenter.Application;
using AuthCenter.Domain;
using AuthCenter.ErrorCode;
using AutoMapper;
using MediatR;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace AuthCenter.Api.Read.Application.Hander.User
{
    public class GetProviceShowHander : IRequestHandler<GetProviceShowCommand, ApiResult<List<ProvinceModel>>>
    {
        private readonly IBaseRepository<UserModel> _userRepository;
        private readonly IBaseRepository<ProvinceModel> _provinceRepository;
        private readonly IMapper _mapper;
        private readonly IBaseRepository<CityModel> _cityRepository;
        private readonly IBaseRepository<CountyModel> _countyRepository;
        private readonly IBaseRepository<RoleModel> _roleRepository;
        private readonly IBaseRepository<UserRoleModel> _userRoleRepository;
        public GetProviceShowHander(IBaseRepository<UserModel> userRepository, IMapper mapper, IBaseRepository<ProvinceModel> provinceRepository, IBaseRepository<CityModel> cityRepository, IBaseRepository<CountyModel> countyRepository, IBaseRepository<RoleModel> roleRepository, IBaseRepository<UserRoleModel> userRoleRepository)
        {
            _userRepository = userRepository;
            _mapper = mapper;
            _provinceRepository = provinceRepository;
            _cityRepository = cityRepository;
            _countyRepository = countyRepository;
            _roleRepository = roleRepository;
            _userRoleRepository = userRoleRepository;
        }
        /// <summary>
        /// 获取省份
        /// </summary>
        /// <returns></returns>
        public Task<ApiResult<List<ProvinceModel>>> Handle(GetProviceShowCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<ProvinceModel>> res=new ApiResult<List<ProvinceModel>>();
            var model = _provinceRepository.GetAll();
            res.Code = ApiEnums.OK;
            res.Message = "获取成功";
            res.Data = model.ToList();
            return Task.FromResult(res);
        }
    }
}
